﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
*/
// JScript File
var valName;
var valSurname;
var valStreet;
var valBuilding;
var valCity;
var valEmail;
var valEmailFormat;
var valPhone;
var valPostCode1;
var valPostCodeData1;
var valCompanyName;
var valCompanyNip;
var valCompanyStreet;
var valCompanyCity;
var valCompanyBulding;
var valCompanyPostCod1;

function ShowSendAbroadSection(obj)
{
   SendAbroadSectionVisibility(obj.checked);
}

function ShowCompanySection(obj)
{
    CompanySectionVisibility(obj.checked);
}

function ShowCompanyAddressSection(obj)
{
    CompanyAddressSectionVisibility(!(obj.checked));
}

function ctrlCustomerData_SetVisibilityOnLoad(chbAbroadName, chbInvoiceName, chbSameAddressName)
{
    SendAbroadSectionVisibility(window.document.getElementById(chbAbroadName).checked);
    var obj = window.document.getElementById(chbInvoiceName);
    if (obj) {
        CompanySectionVisibility(obj.checked);
    }
    else {
        CompanySectionVisibility(false);
    }
    CompanyAddressSectionVisibility(!(window.document.getElementById(chbSameAddressName).checked));
}

function ctrlCustomerData_SetElementOnLoad( valCompanyNameName, valCompanyNipName, valCompanyStreetName, valCompanyCityName, valCompanyBuldingName, valCompanyPostCodeName1, valNameName, valSurnameName, valStreetName, valBuildingName, valCityName, valEmailName, valEmailFormatName, valPhoneName, valPostCode1Name )  
{
    valBuilding = window.document.getElementById(valBuildingName);
    valCity = window.document.getElementById(valCityName);
    valEmail = window.document.getElementById(valEmailName);
    valEmailFormat = window.document.getElementById(valEmailFormatName);
    valName = window.document.getElementById(valNameName);
    valPhone = window.document.getElementById(valPhoneName);
    valPostCode1 = window.document.getElementById(valPostCode1Name);
    valSurname = window.document.getElementById(valSurnameName);
    valStreet = window.document.getElementById(valStreetName);
    
    valCompanyName = window.document.getElementById(valCompanyNameName);
    valCompanyNip = window.document.getElementById(valCompanyNipName);
    valCompanyStreet = window.document.getElementById(valCompanyStreetName);
    valCompanyCity = window.document.getElementById(valCompanyCityName);
    valCompanyBulding = window.document.getElementById(valCompanyBuldingName);
    valCompanyPostCod1 = window.document.getElementById(valCompanyPostCodeName1);
}

function SendAbroadSectionVisibility(show)
{
     if(show)
    {
        window.document.getElementById("rowAbroad").style.display = '';
        window.document.getElementById("send-abroad-info").style.display = '';
    }
    else
    {
        window.document.getElementById("rowAbroad").style.display = 'none';
        window.document.getElementById("send-abroad-info").style.display = 'none';
    }
}

function CompanySectionVisibility(show)
{
    if(show)
    {
        window.document.getElementById("company-data").style.display = '';
        valCompanyName.enabled = true;
        valCompanyNip.enabled = true;
    }
    else
    {
         window.document.getElementById("company-data").style.display = 'none';
         valCompanyName.enabled = false;
         valCompanyNip.enabled = false;
         valCompanyStreet.enabled = false;
         valCompanyCity.enabled = false;
         valCompanyBulding.enabled = false;
         valCompanyPostCod1.enabled = false;
    }
}

function CompanyAddressSectionVisibility(show)
{
    if(show)
    {
        window.document.getElementById("table-company-address").style.display = '';
        valCompanyStreet.enabled = true;
        valCompanyCity.enabled = true;
        valCompanyBulding.enabled = true;
        valCompanyPostCod1.enabled = true;
    }
    else
    {
        window.document.getElementById("table-company-address").style.display = 'none';
        valCompanyStreet.enabled = false;
        valCompanyCity.enabled = false;
        valCompanyBulding.enabled = false;
        valCompanyPostCod1.enabled = false;
    }
}

function DisabledValidators(val) {
    valBuilding.enabled = !val;
    valCity.enabled = !val;
    valEmail.enabled = !val;
    valEmailFormat.enabled = !val;
    valName.enabled = !val;
    valPhone.enabled = !val;
    valPostCode1.enabled = !val;
    valSurname.enabled = !val;
    valStreet.enabled = !val;
}

function SetAddressSectionVisibility(obj, panel) {

    if (obj.checked) {
        window.document.getElementById(panel).style.display = '';
}
    else {
        window.document.getElementById(panel).style.display = 'none';
    }

    DisabledValidators(!obj.checked);
}